package com.application.Adapter;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.application.Activity.R;
import com.application.Adapter.ViewExerciseAdapter.ViewExercise;

public class ViewExerciseAdapter extends ArrayAdapter<ViewExercise> {
	Context mcontent;
	private int mResources;
	private ArrayList<ViewExercise> exerciseList;
	
	public ViewExerciseAdapter(Context context, int resource,
			ArrayList<ViewExercise> optionList) {
		super(context, resource, optionList);
		mcontent = context;
		exerciseList = optionList;
		mResources = resource;
	}

	@Override
	public int getCount() {
		return exerciseList.size();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position,View convertView, ViewGroup parent) {
		ViewExercise viewExercise = exerciseList.get(position);
		Log.d("PEERDROID","position: " + position);
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater lInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = lInflater.inflate(R.layout.row_viewexercise, null, true);
		}
		if (viewExercise != null) {
			TextView txtcontent = (TextView) rowView.findViewById(R.id.rowexercise_txtcontent);
			TextView txtOption = (TextView) rowView.findViewById(R.id.rowexercise_txtoption);
			txtcontent.setText(viewExercise._content);
			if(viewExercise._typeQuestion != 5)
				txtOption.setText(viewExercise._option);
		}

		return rowView;
	}

	public static class ViewExercise {
		private int _typeQuestion;
		private String _content;
		private String _option;
		public ViewExercise(int type, String content, String option)
		{
			_typeQuestion = type;
			set_content(content);
			set_option(option);
		}
		public void set_typeQuestion(int _typeOption) {
			this._typeQuestion = _typeOption;
		}

		public int get_typeQuestion() {
			return _typeQuestion;
		}
		public void set_content(String _content) {
			this._content = _content;
		}
		public String get_content() {
			return _content;
		}
		public void set_option(String _option) {
			this._option = _option;
		}
		public String get_option() {
			return _option;
		}
	}

}
